package torres.ability;

import java.util.ArrayList;
import java.util.List;

import torres.action.Action;
import torres.entity.Entity;

/**
 * @author Torres
 * Types of abilities that perform actions              // TODO LAME CHANGE THIS LATER
 */
public class ActionAbility extends Ability {
	
	private List<Action> actions;
	
	/**
	 * Constructs a new ActionAbility
	 * @param name Name of ActionAbility
	 */
	public ActionAbility(String name, int id, List<Cost> costs) {
		super(name, id, costs);
		actions = new ArrayList<Action>(100);
	}
	
	/**
	 * Constructs a new ActionAbility
	 * @param name Name of ActionAbility
	 * @param actions List of actions
	 */
	public ActionAbility(String name, int id, List<Action> actions, List<Cost> costs) {
		this(name, id, costs);
		this.setActionList(actions);
	}
	
	/**
	 * Constructs a new ActionaAbility based on existing ActionAbility
	 * @param a ActionAbility to be duplicated
	 */
	public ActionAbility(ActionAbility a) {
		this(a.getName(), a.getID(), a.getActions(), a.getCosts());
	}
	
	
	/**
	 * Uses all actions of ActionAbility
	 */
	public void useAbility() {
		for(Action a : this.getActions())
			a.execute();
	}

	/**
	 * Uses all abilities based on Entity's location and direction
	 * @param e Entity being used for actions
	 */
	public void useAbility(Entity e) {
		for(Action a : this.getActions()) {
			a.setUp(e);
			Thread t = new Thread(a);
			t.setName("AbilityThread" + t.getId());
			t.start();
		}
	}
	
	/**
	 * Sets up the actions of ActionAbility
	 * @param actions the new actionList to set
	 */
	public void setActionList(List<Action> actions) {
		this.actions = actions;
	}

	/**
	 * Returns the actions of ActionAbility
	 * @return the actionList
	 */
	public List<Action> getActions() {
		return actions;
	}
}
